﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Frame.Lib.Core.Tool;
using Frame.Lib.Utilities;
using Frame.Lib.Data;
using Frame.Lib.Common;

public partial class Admin_Tools_GenerateCode : System.Web.UI.Page
{
    private DBHelper dbOper;

    protected void Page_Load(object sender, EventArgs e)
    {
        JSUtil.SetDivHeight(txtContent.ClientID, 130);
        if (!IsPostBack)
        {
            txtConectionString.Text = AppSetting.ConnectionString;
        }
        if (txtConectionString.Text != "")
        {
            dbOper = DBHelper.Instance(txtConectionString.Text);
        }
        else
        {
            dbOper = DBHelper.Instance();
        }

        if (!IsPostBack)
        {
            BindDrp();
        }
    }

    private void BindDrp()
    {
        drpType.Items.Add(new ListItem("实体层", "0"));
        drpType.Items.Add(new ListItem("数据层", "1"));
        drpType.Items.Add(new ListItem("业务层", "2"));
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        try
        {
            GenerateCode generate = new GenerateCode(txtConectionString.Text, txtTableName.Text, txtClassName.Text);
            if (drpType.SelectedValue == "0")
            {
                txtContent.Text = generate.GetInfo();
            }
            else if (drpType.SelectedValue == "1")
            {
                txtContent.Text = generate.GetDAL();
            }
            else
            {
                txtContent.Text = generate.GetBO();
            }
        }
        catch
        {
            JSUtil.Alert("数据库连接错误或表名不存在");
        }
    }

}
